<link href="./css/style.css" rel="stylesheet" type="text/css" />
<div class="main">
<div class="goodlist">
	<p class="tt"><a>首页</a>><a href="goodslist.php">商品管理</a>><span>商品列表</span><a class="abtn2" style="float:right; width:auto; " href="excel.php?act=goodsdc" target="main">导出列表</a></p>
	<div class="div">
		<form method='GET' action="?" class='search' >
			<input type="hidden" name="cplx" value="{$cplx}" />
			<p><span>商品名称</span><input type='text' name='gname' style='width:110px;' placeholder='商品名称' value="{$gname}" /></p>			
			<p><span>商品类型</span>
				<select name='cplx'>
					<option {if($cplx==0)} selected {/if} value='0' >无</option>
					<option {if($cplx==1)} selected {/if} value='1'>{$catarr[1]}</option>
					<option {if($cplx==2)} selected {/if} value='2'>{$catarr[2]}</option>
					<option {if($cplx==3)} selected {/if} value='3'>{$catarr[3]}</option>
				</select>
			</p>
			<p><span>功能</span>
				<select name='tag1'>
					<option {if($tag1==0)} selected {/if} value='0' >所有</option>
					{loop $taglist1 $key as $list}
					<option {if($tag1==$list['Id'])} selected {/if} value='{$list[Id]}' >{$list[name]}</option>
					{/loop}
				</select>
			</p>
			<p><span>材质</span>
				<select name='tag2'>
					<option {if($tag2==0)} selected {/if} value='0' >所有</option>
					{loop $taglist2 $key as $list}
					<option {if($tag2==$list['Id'])} selected {/if} value='{$list[Id]}' >{$list[name]}</option>
					{/loop}
				</select>
			</p>
			<p><span>分类排序</span>
				<select name='type1'>
					<option {if($type1==0)} selected {/if} value='0' >无</option>
					<option {if($type1==1)} selected {/if} value='1'>升序</option>
					<option {if($type1==2)} selected {/if} value='2'>降序</option>
				</select>
			</p>
			<p><span>库存排序</span>
				<select name='type2'>
					<option {if($type2==0)} selected {/if} value='0' >无</option>
					<option {if($type2==1)} selected {/if} value='1'>升序</option>
					<option {if($type2==2)} selected {/if} value='2'>降序</option>
				</select>
			</p>			
			<p><span>销量排序</span>
				<select name='type3'>
					<option {if($type3==0)} selected {/if} value='0' >无</option>
					<option {if($type3==1)} selected {/if} value='1'>升序</option>
					<option {if($type3==2)} selected {/if} value='2'>降序</option>
				</select>
			</p>
			<p><input type='submit' value='立即搜索' /></p>
		</form>
	</div>
	<form action="upfiel_excel_goods.php" method="post" enctype="multipart/form-data">
		<div class="shanchuan">
			<span>导入产品：</span>
			<input type="file" name="file" id="file">
			<input type="text" class="file-upload-input" name="copyFile">
			<button type="button" class="file-upload-button" tabindex="-1">选择文件</button>
			<input type="submit" name="submit" value="确认更新" style="width:100px;">
		</div>
	</form>
	<div class="list">
		{if($msg==1)}
		<table>
			<tr class="li1"><th>编号</th><th>所属分类</th><th>功能</th><th>材质</th><th>商品名称</th><th>市场价</th><th>会员价</th><th>置换费</th><th>库存</th><th>销量</th><th>排序</th><th>首页</th><th>状态</th><th>操作</th></tr>
			{loop $glist $key as $list}
			<tr>
				<td>{$list[Id]}</td>
				<td>[{$catarr[$list[cplx]]}]{$list[name]}</td>
				<td>{$list[tagname1]}</td>
				<td>{$list[tagname2]}</td>
				<td style="text-align:left; padding:0 5px;">
					{if($list['cplx']<3)}
					{if($list['type']==1)}<font style="color:red">[单品]</font>
					{elseif($list['type']==2)}<font style="color:red">[礼包]</font>
					{/if}
					{/if}
					{$list[gname]}
				</td>
				
				<td>{$list[yprice]}</td>
				<td>{$list[cash]}</td>						
					
				<td>{$list[kuaidif]}</td>
				<td>{$list[gtotal]}</td>
				<td>{$list[selltotal]}</td>
				<td>{$list[px]}</td>
				<td>
				    {if($list['index1']==1)}
				    <a class='abtn2 index1' style='display:inline-block;float:none; width:auto; cursor:pointer;' data-id="{$list[Id]}">是</a>
				    {else}
				    <a class='abtn3 index1' style='display:inline-block;float:none; width:auto; cursor:pointer; ' data-id="{$list[Id]}">否</a>
				    {/if}
				</td>
				<td>
				    {if($list['gstate']==1)}
				    <a class='abtn2 gstate' style='display:inline-block;float:none; width:auto;  cursor:pointer;' data-id="{$list[Id]}">{$cpstate[$list[gstate]]}</a>
				    {else}
				    <a class='abtn3 gstate' style='display:inline-block;float:none; width:auto; cursor:pointer; ' data-id="{$list[Id]}">{$cpstate[$list[gstate]]}</a>
				    {/if}
				</td>
				<td style='text-align:center;'><a class='abtn2' style='display:inline-block;float:none; ' href='goodsedit.php?gid={$list[Id]}&cplx={$cplx}&gname={$gname}&tag1={$tag1}&tag2={$tag2}&type1={$type1}&type2={$type2}&type3={$type3}'>编辑</a> <a class='abtn3' onclick='del({$list[Id]})' style='display:inline-block;float:none; '>删除</a></td>
			</tr>
			{/loop}
		</table>
		{$page}
		{else}
		<p class='none'>未查询到相关信息</p>
		{/if}
	</div>
	<script src="./js/jquery.js"></script>
	<script>
		$(".file-upload-button").click(function() {
		    $("#file").click();
		});
		// 监听文件输入框的change事件
        $('#file').on('change', function() {
        // 获取文件输入框的值
            var filePath = $(this).val();
        // 使用split函数获取文件名部分
            var fileName = filePath.split('\\').pop();
        // 输出文件名
            $("input[name=copyFile]").val(fileName);
        });
	    $(".index1").on("click",function(){
	       var e = $(this);
	       var id = e.attr('data-id');
	       $.ajax({
				type:"post",
				dataType:"json",
				url:"/Moudel.php?m=g&a=gindex",
				data:"id="+id,
				success:function(d){
					if(d[0]==0){
						alert(d[1]);
					}else{
					    e.removeClass('abtn'+d[1]);
					    e.addClass('abtn'+d[2]);
					    e.html(d[3]);
					}
				}
			});
	    });
	     $(".gstate").on("click",function(){
	       var e = $(this);
	       var id = e.attr('data-id');
	       $.ajax({
				type:"post",
				dataType:"json",
				url:"/Moudel.php?m=g&a=gstate",
				data:"id="+id,
				success:function(d){
					if(d[0]==0){
						alert(d[1]);
					}else{
					    e.removeClass('abtn'+d[1]);
					    e.addClass('abtn'+d[2]);
					    e.html(d[3]);
					}
				}
			});
	    });
		function del(id){
			var message = confirm("确认删除？");
			if(message == true){	
				$.ajax({
					type:"post",
					dataType:"json",
					url:"/Moudel.php?m=g&a=gooddel",
					data:"id="+id,
					success:function(d){
						if(d[0]==0){
							alert(d[1]);
						}
						else{
							alert(d[1]);
							window.location.href='goodslist.php';
						}
					}
				});
			}
			}
	</script>

</div>
</div>
<script>
	h1 = $(".main").height();
	h2 = $(".goodlist").height();
	if(h2>h1){
		$(".main").css("height","auto");
	}
	$('tr').click(function(){	
			$('tr').removeClass('onactive');
			$(this).addClass('onactive');
		});
</script>